
import urllib
import os
import logging
from google.appengine.dist import use_library
use_library('django', '1.2')

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.ext.webapp import template

class Student(db.Model):
  name = db.StringProperty(required=True)
  location = db.StringProperty(required=True)

class MapStudents(webapp.RequestHandler):
    def get(self):
        if self.request.get('name') and self.request.get('location'):
          student = Student(name=self.request.get('name'),
                            location=self.request.get('location'))
          student.put()
        students = Student.all()
        locations = [student.location for student in students]
        labels = []
        i = 0
        for student in students:
          labels.append('f%s,000000,0,%d,10' % (student.name, i))
          i += 1

        template_values = {
          'locations': '|'.join(locations),
          'labels': '|'.join(labels),
        }
        path = os.path.join(os.path.dirname(__file__), 'map.html')
        self.response.out.write(template.render(path, template_values))
        
application = webapp.WSGIApplication(
    [('/', MapStudents)],
    debug=True)

def main():
    run_wsgi_app(application)

def resetdb():

if __name__ == "__main__":
    main()        

